﻿
<template>
    <section>

        <!--工具条-->
        <el-col :span='24' class='toolbar' style='padding-bottom: 0px;'>
            <el-form :inline='true' :model='filters' @submit.native.prevent>
                <el-form-item>
                    <el-input v-model='filters.name' placeholder='名称/Key'></el-input>
                </el-form-item>


                <el-form-item>
                    <el-date-picker type="date" placeholder="选择开始日期" v-model="filters.begin" style="width:180px" format="yyyy年MM月dd日"
                                    value-format="yyyy-MM-dd">></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-date-picker type="date" placeholder="选择结束日期" v-model="filters.end" style="width:180px" format="yyyy年MM月dd日"
                                    value-format="yyyy-MM-dd">></el-date-picker>
                </el-form-item>

                <el-form-item>
                    <el-select style="width: 100%;" v-model="filters.tongDao" placeholder="通道">
                        <el-option v-for="item in list_TongDao" :key="item.TD_Code" :value="item.TD_Code" :label="item.TD_Name">
                            <span style="float: left">{{ item.TD_Name }}</span>
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>

                    <el-select style="width: 100%;" v-model="filters.type" placeholder="物料类型">
                        <el-option v-for="item in typeList" :key="item.value" :value="item.value" :label="item.text">
                            <span style="float: left">{{ item.text }}</span>
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item>
                    <el-button type='primary' @click='getDtoPage'>查询</el-button>
                </el-form-item>


                <el-form-item>
                    <el-button type='primary' @click='ExportDtoPage'>导出</el-button>
                </el-form-item>


                <!--<el-form-item>
                    <el-button type='primary' @click='handleAdd'>新增</el-button>
                </el-form-item>
                <el-button type='danger' @click='batchRemove' :disabled='this.sels.length===0'>批量删除</el-button>-->
            </el-form>
        </el-col>



        <!--列表-->
        <el-table :data='users' highlight-current-row v-loading='listLoading' @selection-change='selsChange'
                  style='width: 100%;'
                  sortable='custom' @sort-change='sortKey'>

            <el-table-column prop='CR_BeginTime' label='开始时间' width='100' :formatter="dateFormat">  </el-table-column>
            <el-table-column prop='CR_EndTime' label='结束时间' width='100' :formatter="dateFormat">  </el-table-column>
            <!--<el-table-column prop='CR_ID' label='' width='' sortable>  </el-table-column>-->
            <el-table-column prop='CR_Type' label='物料类型' width='60' :formatter="wlTypeFormat">  </el-table-column>
            <el-table-column prop='CR_Car' label='车牌号' width='100'>  </el-table-column>
            <!--<el-table-column prop='CR_CardCode' label='车辆卡号' width=''>  </el-table-column>-->
            <el-table-column prop='CR_truckweight' label='车辆标载' width='80'>  </el-table-column>
            <el-table-column prop='CR_TongDaoCode' label='通道编号' width='80'>  </el-table-column>
            <el-table-column prop='CR_Varieties' label='品种' width='100'>  </el-table-column>
            <el-table-column prop='CR_Order' label='订单' width=''>  </el-table-column>
            <!--<el-table-column prop='CR_weightserialcode' label='重量序列号' width=''  >  </el-table-column>-->
            <!--<el-table-column prop='CR_accountcode' label='客户编码' width=''  >  </el-table-column>-->
            <el-table-column prop='CR_accountname' label='客户名称' width=''>  </el-table-column>
            <!--<el-table-column prop='CR_Date' label='装载日期' width=''  >  </el-table-column>-->

            <el-table-column prop='CR_Orderpreweight' label='请发量' width='80'>  </el-table-column>
            <el-table-column prop='CR_LoadingCapacity' label='装载量' width='80'>  </el-table-column>


            <!--<el-table-column label='操作' width='150'>
                <template scope='scope'>
                    <el-button size='small' @click='handleEdit(scope.$index, scope.row)'> 详情 </el-button>
                    <el-button type = 'danger' size = 'small' @click = 'handleDel(scope.$index, scope.row)' > 删除 </el-button>
                </template>
            </el-table-column>-->

        </el-table>



        <!-- 工具条 ,分页 -->
        <el-col :span='24' class='toolbar'>

            <!--<el-pagination layout='prev, pager, next' @current-change='handleCurrentChange' :page-size='50'
                           :total='total' style='float:right;'>
            </el-pagination>-->

            <el-pagination @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="pageIndex"
                           :page-sizes="[ 20, 50, 100]"
                           :page-size="pageSize"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="total"
                           style='float:right;'>
            </el-pagination>


        </el-col>



        <!--编辑界面-->
        <el-dialog title='编辑' :visible.sync='editFormVisible' v-model='editFormVisible' :close-on-click-modal='false'>
            <el-form :model='editForm' label-width='80px' :rules='editFormRules' ref='editForm'>

                <el-form-item label='' prop='CR_ID'>
                    <el-input v-model='editForm.CR_ID' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='装载类型' prop='CR_Type'>
                    <el-input v-model='editForm.CR_Type' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='车牌号' prop='CR_Car'>
                    <el-input v-model='editForm.CR_Car' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='车辆卡号' prop='CR_CardCode'>
                    <el-input v-model='editForm.CR_CardCode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='车辆标载' prop='CR_truckweight'>
                    <el-input v-model='editForm.CR_truckweight' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='通道编号' prop='CR_TongDaoCode'>
                    <el-input v-model='editForm.CR_TongDaoCode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='品种' prop='CR_Varieties'>
                    <el-input v-model='editForm.CR_Varieties' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='订单' prop='CR_Order'>
                    <el-input v-model='editForm.CR_Order' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='重量序列号' prop='CR_weightserialcode'>
                    <el-input v-model='editForm.CR_weightserialcode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='客户编码' prop='CR_accountcode'>
                    <el-input v-model='editForm.CR_accountcode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='客户名称' prop='CR_accountname'>
                    <el-input v-model='editForm.CR_accountname' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='装载日期' prop='CR_Date'>
                    <el-input v-model='editForm.CR_Date' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='开始时间' prop='CR_BeginTime'>
                    <el-input v-model='editForm.CR_BeginTime' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='结束时间' prop='CR_EndTime'>
                    <el-input v-model='editForm.CR_EndTime' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='请发量' prop='CR_Orderpreweight'>
                    <el-input v-model='editForm.CR_Orderpreweight' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='装载量' prop='CR_LoadingCapacity'>
                    <el-input v-model='editForm.CR_LoadingCapacity' auto-complete='off'></el-input>
                </el-form-item>


            </el-form>
            <div slot='footer' class='dialog-footer'>
                <el-button @click.native='editFormVisible = false'>取消</el-button>
                <el-button type='primary' @click.native='editSubmit' :loading='editLoading'>提交</el-button>
            </div>
        </el-dialog>


        <!--新增界面-->
        <el-dialog title='新增' :visible.sync='addFormVisible' v-model='addFormVisible' :close-on-click-modal='false'>
            <el-form :model='addForm' label-width='80px' :rules='addFormRules' ref='addForm'>



                <el-form-item label='' prop='CR_ID'>
                    <el-input v-model='addForm.CR_ID' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='装载类型' prop='CR_Type'>
                    <el-input v-model='addForm.CR_Type' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='车牌号' prop='CR_Car'>
                    <el-input v-model='addForm.CR_Car' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='车辆卡号' prop='CR_CardCode'>
                    <el-input v-model='addForm.CR_CardCode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='车辆标载' prop='CR_truckweight'>
                    <el-input v-model='addForm.CR_truckweight' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='通道编号' prop='CR_TongDaoCode'>
                    <el-input v-model='addForm.CR_TongDaoCode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='品种' prop='CR_Varieties'>
                    <el-input v-model='addForm.CR_Varieties' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='订单' prop='CR_Order'>
                    <el-input v-model='addForm.CR_Order' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='重量序列号' prop='CR_weightserialcode'>
                    <el-input v-model='addForm.CR_weightserialcode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='客户编码' prop='CR_accountcode'>
                    <el-input v-model='addForm.CR_accountcode' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='客户名称' prop='CR_accountname'>
                    <el-input v-model='addForm.CR_accountname' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='装载日期' prop='CR_Date'>
                    <el-input v-model='addForm.CR_Date' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='开始时间' prop='CR_BeginTime'>
                    <el-input v-model='addForm.CR_BeginTime' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='结束时间' prop='CR_EndTime'>
                    <el-input v-model='addForm.CR_EndTime' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='请发量' prop='CR_Orderpreweight'>
                    <el-input v-model='addForm.CR_Orderpreweight' auto-complete='off'></el-input>
                </el-form-item>


                <el-form-item label='装载量' prop='CR_LoadingCapacity'>
                    <el-input v-model='addForm.CR_LoadingCapacity' auto-complete='off'></el-input>
                </el-form-item>



            </el-form>
            <div slot='footer' class='dialog-footer'>
                <el-button @click.native='addFormVisible = false'>取消</el-button>
                <el-button type='primary' @click.native='addSubmit' :loading='addLoading'>提交</el-button>
            </div>
        </el-dialog>





    </section>
</template>

<script>

    //import * as fecha from ""
    //import util from '../../../util/date'
    import * as fecha from "element-ui/lib/utils/date";
    import { testapi, GetList_DTSN_TongDao, ExportURL_DTSN_CanningRecord, Export_DTSN_CanningRecord, getPage_DTSN_CanningRecord, getByID_DTSN_CanningRecord, edit_DTSN_CanningRecord, add_DTSN_CanningRecord, batchRemove_DTSN_CanningRecord, Remove_DTSN_CanningRecord } from '../../api/api';

    export default {
        data() {   // 全局变量
            return {
                typeList: [{ text: '请选择物料类型', value: 0 }, { text: '熟料', value: 1 }, { text: '散料', value: 2 }],
                list_TongDao: [],
                filters: { name: '', tongDao: '', type: 0 },
                users: [],
                total: 0,
                pageSize: 20,
                pageIndex: 1,
                listLoading: false,
                sels: [],//列表选中列
                addDialogFormVisible: false,
                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    CR_ID: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CR_Type: [{ required: true, message: '请输入装载类型', trigger: 'blur' }],
                    CR_Car: [{ required: true, message: '请输入车牌号', trigger: 'blur' }],
                    CR_CardCode: [{ required: true, message: '请输入车辆卡号', trigger: 'blur' }],
                    CR_truckweight: [{ required: true, message: '请输入车辆标载', trigger: 'blur' }],
                    CR_TongDaoCode: [{ required: true, message: '请输入通道编号', trigger: 'blur' }],
                    CR_Varieties: [{ required: true, message: '请输入品种', trigger: 'blur' }],
                    CR_Order: [{ required: true, message: '请输入订单', trigger: 'blur' }],
                    CR_weightserialcode: [{ required: true, message: '请输入重量序列号', trigger: 'blur' }],
                    CR_accountcode: [{ required: true, message: '请输入客户编码', trigger: 'blur' }],
                    CR_accountname: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
                    CR_Date: [{ required: true, message: '请输入装载日期', trigger: 'blur' }],
                    CR_BeginTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
                    CR_EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
                    CR_Orderpreweight: [{ required: true, message: '请输入请发量', trigger: 'blur' }],
                    CR_LoadingCapacity: [{ required: true, message: '请输入装载量', trigger: 'blur' }],
                }
                ,
                //编辑界面数据
                editForm: {
                    CR_ID: 0,
                    CR_Type: 0,
                    CR_Car: '',
                    CR_CardCode: '',
                    CR_truckweight: '',
                    CR_TongDaoCode: '',
                    CR_Varieties: '',
                    CR_Order: '',
                    CR_weightserialcode: '',
                    CR_accountcode: '',
                    CR_accountname: '',
                    CR_Date: 0,
                    CR_BeginTime: 0,
                    CR_EndTime: 0,
                    CR_Orderpreweight: 0,
                    CR_LoadingCapacity: 0,
                }
                ,
                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    CR_ID: [{ required: true, message: '请输入', trigger: 'blur' }],
                    CR_Type: [{ required: true, message: '请输入装载类型', trigger: 'blur' }],
                    CR_Car: [{ required: true, message: '请输入车牌号', trigger: 'blur' }],
                    CR_CardCode: [{ required: true, message: '请输入车辆卡号', trigger: 'blur' }],
                    CR_truckweight: [{ required: true, message: '请输入车辆标载', trigger: 'blur' }],
                    CR_TongDaoCode: [{ required: true, message: '请输入通道编号', trigger: 'blur' }],
                    CR_Varieties: [{ required: true, message: '请输入品种', trigger: 'blur' }],
                    CR_Order: [{ required: true, message: '请输入订单', trigger: 'blur' }],
                    CR_weightserialcode: [{ required: true, message: '请输入重量序列号', trigger: 'blur' }],
                    CR_accountcode: [{ required: true, message: '请输入客户编码', trigger: 'blur' }],
                    CR_accountname: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
                    CR_Date: [{ required: true, message: '请输入装载日期', trigger: 'blur' }],
                    CR_BeginTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
                    CR_EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
                    CR_Orderpreweight: [{ required: true, message: '请输入请发量', trigger: 'blur' }],
                    CR_LoadingCapacity: [{ required: true, message: '请输入装载量', trigger: 'blur' }],
                }
                ,
                //新增界面数据
                addForm: {
                    CR_Type: 0,
                    CR_Car: '',
                    CR_CardCode: '',
                    CR_truckweight: '',
                    CR_TongDaoCode: '',
                    CR_Varieties: '',
                    CR_Order: '',
                    CR_weightserialcode: '',
                    CR_accountcode: '',
                    CR_accountname: '',
                    CR_Date: 0,
                    CR_BeginTime: 0,
                    CR_EndTime: 0,
                    CR_Orderpreweight: 0,
                    CR_LoadingCapacity: 0,
                }

            }
        },
        methods: {    // 全局方法
            //性别显示转换
            //formatSex: function (row, column) {
            //    return row.C_Value == 2 ? '男' : row.C_Value;
            //},
            //formatterCreateTime: function (row, column) {
            //    return (!row.C_CreateTime || row.C_CreateTime == '') ? '' : util.formatDate.format(new Date(row.C_CreateTime), 'yyyy-MM-dd');
            //},


            dateFormat(row, column, cellValue) {
                return cellValue ? fecha.format(new Date(cellValue), 'yyyy-MM-dd HH:mm:ss') : '';
            },

            wlTypeFormat(row, column, cellValue) {
                if (cellValue == 1) {
                    //熟料', value: 1 }, { text: '散料', value: 2
                    return '熟料';
                }
                else {
                    return '散料';
                }
            },

            handleCurrentChange(val) {
                this.pageIndex = val;
                this.getDtoPage();
            },
            // 每页数
            handleSizeChange(val) {
                this.pageSize = val;
                this.pageIndex = 1;
                this.getDtoPage();
            },

            // 测试
            sortKey(val) {
                // console.log(val)
            },


            //获取用户列表
            getDtoPage() {
                //let para = {
                //    page: this.page,
                //    key: this.filters.name
                //};

                let para = {
                    page: this.pageIndex,
                    pageSize: this.pageSize,
                    sidx: this.sidx,
                    order: this.order,
                    tongDao: this.filters.tongDao,
                    key: this.filters.name,
                    begin: this.filters.begin,
                    end: this.filters.end,
                    type: this.filters.type
                };


                this.listLoading = true;

                testapi();

                getPage_DTSN_CanningRecord(para).then((res) => {

                    this.total = res.data.response.dataCount;
                    this.users = res.data.response.data;
                    this.listLoading = false;

                });
            },

            ExportDtoPage() {

                let para = {
                    page: this.pageIndex,
                    pageSize: this.pageSize,
                    sidx: this.sidx,
                    order: this.order,
                    tongDao: this.filters.tongDao,
                    key: this.filters.name,
                    begin: this.filters.begin,
                    end: this.filters.end,
                    type: this.filters.type
                };


                // this.listLoading = true;

                testapi();

                ExportURL_DTSN_CanningRecord(para).then((res) => {
                     
                    window.location.href = res.data.response;
                    //window.location.href = 'http://localhost:8082/Excel/装载记录_20200707162708.xlsx';
                });


                //Export_DTSN_CanningRecord(para).then((res) => {
                //    console.log(res)
                //    const link = document.createElement('a')
                //    let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
                //    link.style.display = 'none'
                //    link.href = URL.createObjectURL(blob);
                //    let num = ''
                //    for (let i = 0; i < 10; i++) {
                //        num += Math.ceil(Math.random() * 10)
                //    }
                //    link.setAttribute('download', '用户_' + num + '.xlsx')
                //    document.body.appendChild(link)
                //    link.click()
                //    document.body.removeChild(link)
                //});



            },

            //删除
            handleDel: function (index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = { id: row.CR_ID };
                    Remove_DTSN_CanningRecord(para).then((res) => {
                        if (util.isEmt.format(res)) {
                            this.listLoading = false;
                            return;
                        }
                        this.listLoading = false;
                        if (res.data.success) {
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                        } else {
                            this.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }
                        this.getDtoPage();
                    });
                }).catch((c) => {
                    console.log(c);
                });
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true;

                let para_getGetByID = { id: row.CR_ID };

                getByID_DTSN_CanningRecord(para_getGetByID).then((getDto) => {

                    this.editForm = Object.assign({}, getDto.data.response);
                });
            },
            //显示新增界面
            handleAdd() {
                this.addFormVisible = true;
                this.addForm = {
                    CR_Type: 0,
                    CR_Car: '',
                    CR_CardCode: '',
                    CR_truckweight: '',
                    CR_TongDaoCode: '',
                    CR_Varieties: '',
                    CR_Order: '',
                    CR_weightserialcode: '',
                    CR_accountcode: '',
                    CR_accountname: '',
                    CR_Date: 0,
                    CR_BeginTime: 0,
                    CR_EndTime: 0,
                    CR_Orderpreweight: 0,
                    CR_LoadingCapacity: 0,
                }
                    ;
            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                        }).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.editForm);

                            edit_DTSN_CanningRecord(para).then((res) => {

                                if (util.isEmt.format(res)) {
                                    this.editLoading = false;
                                    return;
                                }
                                if (res.data.success) {
                                    this.editLoading = false;

                                    this.$message({
                                        message: res.data.msg,
                                        type: 'success'
                                    });
                                    this.$refs['editForm'].resetFields();
                                    this.editFormVisible = false;
                                    this.getDtoPage();
                                } else {
                                    this.$message({
                                        message: res.data.msg,
                                        type: 'error'
                                    });
                                }
                            });
                        });
                    }
                });
            },
            //新增
            addSubmit: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                        }).then(() => {
                            this.addLoading = true;
                            let para = Object.assign({}, this.addForm);

                            add_DTSN_CanningRecord(para).then((res) => {

                                if (util.isEmt.format(res)) {
                                    this.addLoading = false;
                                    return;
                                }

                                if (res.data.success) {
                                    this.addLoading = false;
                                    this.$message({
                                        message: res.data.msg,
                                        type: 'success'
                                    });
                                    this.$refs['addForm'].resetFields();
                                    this.addFormVisible = false;
                                    this.getDtoPage();
                                }
                                else {
                                    this.$message({
                                        message: res.data.msg,
                                        type: 'error'
                                    });
                                }
                            });
                        });
                    }
                });
            },
            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {

                var ids = this.sels.map(item => item.CR_ID).toString();
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning',
                    confirmButtonText: '确定',
                    cancelButtonText: '取消'
                }).then(() => {
                    this.listLoading = true;
                    let para = { ids: ids };

                    batchRemove_DTSN_CanningRecord(para).then((res) => {
                        this.listLoading = false;

                        if (res.data.success) {
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                        } else {
                            this.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }
                        this.getDtoPage();
                    });
                }).catch(() => {

                });
            }
        },
        mounted() {
            this.getDtoPage();


            GetList_DTSN_TongDao().then((res) => {

                this.list_TongDao = res.data.response;
                 

            });

        }
    }

</script>

<style scoped>
</style>
